package cn.com.jtang.wedding.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.com.jtang.wedding.model.Application;
import cn.com.jtang.wedding.model.User;
import cn.com.jtang.wedding.service.ApplicationManager;

import com.opensymphony.xwork2.Preparable;

public class ApplicationAction extends BaseAction implements Preparable {
	
	private ApplicationManager applicationManager;
	private Application application;
	private List<Application> applications;
	Map<String, Object> map = new HashMap<String, Object>();
	 
    private long aid;
	private String id;
	private String companyName;		//必填 	公司名
	private String telephone;		//必填	公司电话
	private String contact;			//必填	联系人
	private String address;			//必填	地址

	public void prepare() throws Exception {
		// TODO Auto-generated method stub

	}
	/**
	 * 获取所有记录列表
	 */
	public String getAll(){		
		pageNum = (pageNum) <= 0 ? 1 : pageNum;
		//map.put("parentId", getCurrentAdminUser().getId());
		//int count = applicationManager.getCount(map);
		int count = applicationManager.getCount(null);
		applications = new ArrayList<Application>();
		pageCount = (int) Math.ceil((double) count / (double) pageSize);
		pageCount=pageCount==0?1:pageCount;
		pageNum = pageNum > pageCount ? pageCount : pageNum;
		applications = applicationManager.queryAll(null, pageSize * (pageNum - 1),
				pageSize * pageNum);
		return SUCCESS;
	}
	
	public String viewApplication(){
		aid = new Long(id).longValue();
		application = applicationManager.queryById(aid);	
		return SUCCESS;
	}
	
	public String doAddApplication() {
		Application application = new Application();
		application.setCompanyName(this.getCompanyName());
		application.setContact(this.getContact());
		application.setTelephone(this.getTelephone());
		application.setAddress(this.getAddress());
		applicationManager.insert(application);
		return SUCCESS;
	}

	public ApplicationManager getApplicationManager() {
		return applicationManager;
	}

	public void setApplicationManager(ApplicationManager applicationManager) {
		this.applicationManager = applicationManager;
	}

	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public List<Application> getApplications() {
		return applications;
	}

	public void setApplications(List<Application> applications) {
		this.applications = applications;
	}

	public Map<String, Object> getMap() {
		return map;
	}

	public void setMap(Map<String, Object> map) {
		this.map = map;
	}

	public long getAid() {
		return aid;
	}

	public void setAid(long aid) {
		this.aid = aid;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	/**
	 * @return the companyName
	 */
	public String getCompanyName() {
	
		return companyName;
	}
	
	/**
	 * @param companyName the companyName to set
	 */
	public void setCompanyName(String companyName) {
	
		this.companyName = companyName;
	}
	
	/**
	 * @return the telephone
	 */
	public String getTelephone() {
	
		return telephone;
	}
	
	/**
	 * @param telephone the telephone to set
	 */
	public void setTelephone(String telephone) {
	
		this.telephone = telephone;
	}
	
	/**
	 * @return the contact
	 */
	public String getContact() {
	
		return contact;
	}
	
	/**
	 * @param contact the contact to set
	 */
	public void setContact(String contact) {
	
		this.contact = contact;
	}
	
	/**
	 * @return the address
	 */
	public String getAddress() {
	
		return address;
	}
	
	/**
	 * @param address the address to set
	 */
	public void setAddress(String address) {
	
		this.address = address;
	}
	

}
